home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / AppKiller / trapavail.c < prev    next >
Text File  |  1991-12-04  |  1KB  |  45 lines

  1. /*
  2. ** trapavail.c
  3. **
  4. ** this is the code supporting Apple's official method
  5. ** of checking for the existence of a specific trap.
  6. ** See p. 3-8 of IM-VI for the details.
  7. */
  8.  
  9.  
  10. #include <OSUtils.h>
  11. #include <Traps.h>
  12. #include <Types.h>
  13.  
  14. #include "trapavail.h"
  15.  
  16. static int NumToolboxTraps(void);
  17. static TrapType GetTrapType(int);
  18. /*=================================================== */
  19.  
  20. static int NumToolboxTraps(void)
  21. {
  22.     return ( (NGetTrapAddress(_InitGraf, ToolTrap)==
  23.               NGetTrapAddress(0xAA6e, ToolTrap)) ? 0x0200 : 0x0400);
  24. } /* NumToolboxTraps() */
  25.  
  26.  
  27. static TrapType GetTrapType(int theTrap)
  28. {
  29.     unsigned TrapMask = 0x0800;
  30.     return ((theTrap & TrapMask)>0 ? ToolTrap : OSTrap);
  31. } /* GetTrapType() */
  32.  
  33.  
  34. Boolean TrapAvailable(int theTrap)
  35. {
  36.     TrapType tType = GetTrapType( theTrap);
  37.     if (tType == ToolTrap) {
  38.         theTrap = (int)theTrap & (int)0x07ff;
  39.         if (theTrap >= NumToolboxTraps())
  40.             theTrap = _Unimplemented;
  41.     }
  42.     return (Boolean)(NGetTrapAddress(theTrap, tType) !=
  43.             NGetTrapAddress(_Unimplemented, ToolTrap));
  44. } /* TrapAvailable() */
  45.